﻿@model QRCode.ViewModel.UserInfoViewModel

@{
    ViewBag.Title = "用户信息";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<ol class="breadcrumb">
    <li><span class="glyphicon glyphicon-home"></span>  @Html.ActionLink("首页", "Index", "Scan")</li>
    <li>@Html.ActionLink("用户信息", "UserInfo", "Authentication")</li>
</ol>
<div>
    <dl class="dl-horizontal col-md-6 col-md-offset-3">
        <dt>
            @Html.DisplayNameFor(model => model.Username)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.Username)
        </dd>
        <dt>
            <input value="" style="opacity:0;"/>
        </dt>
        <dd>

        </dd>
        <dt>
            @Html.DisplayNameFor(model => model.Name)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.Name)
            <button type="button" id="btn_name" class="btn btn-xs btn-danger pull-right">修改</button>
        </dd>
        <dt>
            <input value="" style="opacity:0;" />
        </dt>
        <dd>

        </dd>

        <dt>
            @Html.DisplayNameFor(model => model.Password)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.Password)            
            <button type="button" id="btn_pwd" class="btn btn-xs btn-danger pull-right">修改</button>
        </dd>
        <dt>
            <input value="" style="opacity:0;" />
        </dt>
        <dd>

        </dd>
        <dt>
            @Html.DisplayNameFor(model => model.Email)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.Email)
            @*<button type="button" id="btn_email" class="btn btn-xs btn-danger pull-right">修改</button>*@
        </dd>
    </dl>
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
    @Scripts.Render("~/bundles/bootstrapplugin")
    <script type="text/javascript">
        $(document).ready(function () {
            //修改密码开始
            $("#btn_pwd").click(function () {
                var addDialog = new BootstrapDialog({
                    title: "<span class='glyphicon glyphicon-plus'></span>修改用户密码",
                    message: function (dialog) {
                        var $message = $('<div></div>');
                        var pageToLoad = dialog.getData('pageToLoad');
                        $message.load(pageToLoad);

                        return $message;
                    },
                    data: {
                        'pageToLoad': '@Url.Action("ChangePwdPartialView")'
                    },
                    buttons: [{
                        icon: "glyphicon glyphicon-plus",
                        label: "提交",
                        action: function (dialogItself) {
                            $.post($("form").attr("action"), $("form").serializeArray(), function (data) {
                                if (data.Code == 1) {
                                    BootstrapDialog.show({
                                        message: data.Message,
                                        buttons: [{
                                            icon: "glyphicon glyphicon-ok",
                                            label: "确定",
                                            action: function (dialogItself) {
                                                //$table.bootstrapTable("refresh");
                                                dialogItself.close();
                                                addDialog.close();
                                            }
                                        }]

                                    });
                                }
                                else {
                                    BootstrapDialog.alert(data.Message);
                                    $("#Password").val("");
                                    $("#ConfirmPassword").val("");
                                    //var pwd = dialogItself.getModalBody().find('#Password');
                                    //var pwdc = dialogItself.getModalBody().find('#ConfirmPassword');
                                    //pwd.val("");
                                    //pwdc.val("");
                                }
                            }, "json");
                            $("form").validate();
                        }
                    }, {
                        icon: "glyphicon glyphicon-remove",
                        label: "关闭",
                        action: function (dialogItself) {
                            dialogItself.close();
                        }
                    }]
                });
                addDialog.open();
            });
            //修改密码结束
            //修改昵名开始
            $("#btn_name").click(function () {
                var addDialog = new BootstrapDialog({
                    title: "<span class='glyphicon glyphicon-plus'></span>修改昵名",
                    message: function (dialog) {
                        var $message = $('<div><div class="form-horizontal"><div class="form-group"><label class="control-label col-md-2" for="name">昵名</label><div class="col-md-10"><input class="form-control text-box single-line" id="name" name="name"></input></div></div></div></div>');
                        //var pageToLoad = dialog.getData('pageToLoad');
                        //$message.load(pageToLoad）
                        return $message;
                    },
                    data: {
                        'pageToLoad': ''
                    },
                    buttons: [{
                        icon: "glyphicon glyphicon-plus",
                        label: "修改",
                        action: function (dialogItself) {
                            var name = $('#name').val();
                            $.post("@Url.Action("ChangeNamePartialView", "Authentication")", { name:name}, function (data) {
                                    if (data.Code == 1) {
                                        BootstrapDialog.show({
                                            message: data.Message,
                                            buttons: [{
                                                icon: "glyphicon glyphicon-ok",
                                                label: "确定",
                                                action: function (dialogItself) {
                                                    //$table.bootstrapTable("refresh");
                                                    dialogItself.close();
                                                    addDialog.close();
                                                    location.reload();
                                                }
                                            }]

                                        });
                                    }
                                    else {
                                        BootstrapDialog.alert(data.Message);
                                    }
                            }, "json");
                            $("form").validate();
                        }
                    }, {
                        icon: "glyphicon glyphicon-remove",
                        label: "关闭",
                        action: function (dialogItself) {
                            dialogItself.close();
                        }
                    }]
                });
                addDialog.open();
            });
            //修改匿名结束
           
        });
    </script>
}